//
//  BannerAdM.m
//  TestDemo
//
//  Created by a on 2023/2/8.
//

#import "BannerAdM.h"
#import <LDMobileAdSDK/LDMobileAdSDK.h>

@interface BannerAdM ()<LDBannerAdDelegate>

@property (nonatomic,strong)LDBannerAdView * ad;

@end

@implementation BannerAdM


- (void)setupAd{
    
}

- (void)setup{
    [LDSDKConfig setAppKey:@"f7d19924efe93778" token:@"cvvcqdnyrk"];
    CGFloat adWidth = self.viewController.view.bounds.size.width;
    CGFloat adHeight = adWidth / 6.4;
    self.ad = [[LDBannerAdView alloc]initWithSlotID:@"2151738" viewController:self.viewController adSize:CGSizeMake(adWidth, adHeight)];
    self.ad.delegate = self;
    self.ad.autoSwitchInterval = 30;
}

- (void)loadAdShowInView:(UIView*)containView{
    [self setup];
    [containView addSubview:self.ad];
    self.ad.frame = containView.bounds;
    [self.ad loadAdShow];
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [self.ad removeFromSuperview];
//        self.ad = nil;
//    });
}

- (void)loadAd{
    
}

- (void)showAd{
}

- (void)dealloc{
    NSLog(@"BannerAdM dealloc");
}

#pragma mark -LDBannerAdDelegate
///banner加载成功
- (void)bannerAdDidLoad:(LDBannerAdView *)bannerAdView{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
}

///banner失败
- (void)bannerAdFail:(LDBannerAdView *)bannerAdView error:(NSError *)error{
    NSLog(@"---------%@,%@",NSStringFromSelector(_cmd),error);
}

///banner触发点击
- (void)bannerAdClick:(LDBannerAdView *)bannerAdView{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
}

///banner曝光
- (void)bannerAdDidExposure:(LDBannerAdView *)bannerAdView{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
}

///banner关闭
- (void)bannerAdClose:(LDBannerAdView *)bannerAdView{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
    [bannerAdView removeFromSuperview];
    self.ad = nil;
}

@end


